<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!--0:引入 vue.js-->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <!--0:引入 axios.js-->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    
</head>
<body>   
    <div id ="app3">
        <div v-if="isLogin" >
            欢迎 钉钉            
            <!-- <button  @click="logout">注销</button> -->
            <a href="" @click.prevent="logout">注销</a>

        </div>        
        <div v-else>
            用户 <input type="text" v-model = "uname">  密码  <input type="text" v-model = "upwd">
            <a href="" @click.prevent = "login" >登录</a>|<a href="">注册</a>
        </div>
    </div>
    <script>
        //配合axios调用时的基本URL
        //axios.defaults.baseURL="http://115.159.160.93:8080";
        axios.defaults.baseURL="http://localhost:5050";
        var vm = new Vue({
            el:"#app3",
            data:{
                isLogin:false,
                uname:"dingding",
                upwd:"123456",
            },
            methods: {
                logout(){
                    console.log("logout。。。。");
                    //this.isLogin=false;
                    axios.get("/user/logout").then(r=>{
                        if(r.data.code==200){
                            this.isLogin=false;
                        }
                    })
                },

                login(){
                    //this.isLogin=true;
                    //判断用户 密码 是否合法用户 登录验证
                    let uname =  this.uname;
                    let upwd = this.upwd;                    
                    axios.post("/user/login",{uname,upwd}).then(result=>{
                        console.log(result.data);
                        if(result.data.code==200){
                            this.isLogin = true;
                        }
                    })
                },

                async login2(){
                    //this.isLogin=true;
                    //判断用户 密码 是否合法用户 登录验证
                    let uname =  this.uname;
                    let upwd = this.upwd;                    
                    let result  = await axios.post("/user/login",{uname,upwd});
                    
                    console.log("login2:");
                    console.log(result.data);
                    if(result.data.code==200){
                        this.isLogin = true;
                    }
                   
                }
    
            }
        })
    </script>
    
</body>
</html>